package com.hive;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import java.sql.*;
import java.util.List;
import org.slf4j.LoggerFactory;

/**
 * Author:BYDylan
 * Date:2020/9/21
 * Description:
 */
public class HiveDemo {
    static {
        LoggerContext loggerContext = (ch.qos.logback.classic.LoggerContext) LoggerFactory.getILoggerFactory();
        List<Logger> loggerList = loggerContext.getLoggerList();
        loggerList.forEach(logger -> {logger.setLevel(Level.ERROR);});
    }

    public static void main(String[] args) throws SQLException {

        try {
            Class.forName("org.apache.hive.jdbc.HiveDriver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.exit(1);
        }
        //此处用户名需要是有权限操作HDFS的Linux用户
        Connection con = DriverManager.getConnection("jdbc:hive2://192.168.72.102:10000", "root", "");
        Statement stmt = con.createStatement();
        String sql="select * from hive_1.testtable1 ";
//        String sql="desc formatted hive_1.user_info";

        ResultSet res = stmt.executeQuery(sql);
        while (res.next()) {
            System.out.println(res.getString(1) + "\t" + res.getString(2));
        }
    }
}
